//
//  LCFMDB.m
//  LCFMDB
//
//  Created by jiukuyinyue on 2017/10/31.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LCFMDB.h"
#import "LCBaseDatabase+DBCreate.h"//创建
#import "LCBaseDatabase+DBAlter.h"//增加表字段
#import "LCBaseDatabase+DBInsert.h"//增
#import "LCBaseDatabase+DBDelete.h"//删
#import "LCBaseDatabase+DBUpdate.h"//改
#import "LCBaseDatabase+DBSelect.h"//查

@implementation LCFMDB

IMPLEMENTATION_SINGLETON(LCBaseDatabase)

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setupConfig];
    }
    return self;
}

- (void)setupConfig{
    if (self.dbVersion == 0) {//没有创建的时候 版本为0 , init
        NSLog(@"版本为0");
        self.dbVersion += 1;
    }
    if(self.dbVersion == 1){//版本为1的时候
        NSLog(@"版本为1");
        [self createEssayParameters];
        [self alterIDEssayParametersListTable];
        [self alterSrcEssayParametersListTable];
    }

}

- (void)insertHomeEssayTable:(NSArray *)arr cid:(NSString *)cid{
        [self insertEssayTable:arr cid:cid read_history:0];
}
- (void)selectHomeEssayTableWithCid:(NSString *)cid
                          succBlock:(void(^)(NSArray *array))succBlock
                          failBlock:(void(^)(void))failBlock{
     [self selectEssayAtTableId:cid limitCount:20 offsetCount:0 type:SQL_IF_TYPE_FIRST succBlock:^(NSArray *array) {
        succBlock(array);
    } failBlock:^{
        failBlock();
    }];
}
- (void)deleteDB{
    [self delTable:@"EssayTable"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self createEssayParameters];
        [self alterIDEssayParametersListTable];
        [self alterSrcEssayParametersListTable];
    });

}



@end
